package com.zhiyou.app.pojo.enums;


import lombok.Getter;

import java.util.Arrays;

/**
 * @Description 订单类型枚举
 * @Author : bind
 * @Date : 2022-06-14 14:41
 */
@Getter
public enum OrderStatusEnum {
    CREATED("create", "新建"),
    WAIT4PAY("wait_for_pay", "等待付款"),
    PAID("paid", "已付款"),
    PART_PAID("part_paid", "部分付款"),
    FINISHED("finished", "任务完成"),
    CLOSED("closed", "关闭"),
    REFUND_APPLY("refunding", "退款申请中"),
    REFUND("refund", "已退款"),
    REJECT_REFUND("reject_refund", "退款已拒绝"),
    FAIL_REFUND("fail_refund", "退款失败"),
    COMPLETE("complete", "订单完成"),
    ;

    public final String code;
    public final String name;

    OrderStatusEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static boolean contains(String s) {
        return Arrays.stream(OrderStatusEnum.values()).map(OrderStatusEnum::toString).anyMatch(s::equals);
    }

    @Override
    public String toString() {
        return String.valueOf(this.code);
    }

    public static OrderStatusEnum parse(String code) {
        for (OrderStatusEnum msgType : OrderStatusEnum.values()) {
            if (msgType.getCode().equals(code)) {
                return msgType;
            }
        }
        return null;
    }
}
